package com.explorati.LeetCode206.reverseLinkedList;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 23:50 2020/9/12 0012
 * @ Description ：
 */
public class Solution3 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public static ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode cur = head;

        while(cur != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;

        }

        return pre;
    }
}
